package view;

import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.font.TextAttribute;
import java.util.Map;

import javax.swing.BorderFactory;
import javax.swing.JTable;
import javax.swing.border.Border;
import javax.swing.table.DefaultTableCellRenderer;

@SuppressWarnings("serial")
public class YourTableCellRenderer  extends DefaultTableCellRenderer {
	
	Border border = null;
	boolean isBordered = true;
	private int filas;
	private int bestTimeIndex;
	private int topSpeedIndex;
	private int avgSpeedIndex;
	private int minSpeedIndex;
	

	public YourTableCellRenderer(int numvoltes){
		this.filas=numvoltes;
	}
	
	public Component getTableCellRendererComponent(JTable table,
			Object value,
			boolean isSelected,
			boolean hasFocus,
			int row,
			int column) {
		Component c = 
				super.getTableCellRendererComponent(table, value,
						isSelected, hasFocus,
						row, column);
	
		Map  attributes = (new Font("Helvetica", Font.BOLD, 12)).getAttributes();
		attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
		Font font = new Font(attributes);
		
		if (column == 7) { //columna colores
			Color newColor = (Color)value;
			c.setForeground(newColor);
			c.setBackground(newColor);
			border = BorderFactory.createMatteBorder(2,5,2,5,
					table.getBackground());
			setBorder(border);
		}
		
		if (column < 7 && row < filas ) { //filas datos
			c.setBackground(null);
			c.setForeground(Color.GRAY);
			if (isSelected) {
				c.setFont(new Font("Helvetica", Font.BOLD, 12));
				c.setForeground(new Color(232,127,16));
			}
		}
		
		if(column < 7 && row >= filas ){    //filas resumen
			c.setBackground(new Color(70, 100, 45));
			c.setForeground(new Color(0,0,0));
			c.setFont(new Font("Helvetica", Font.BOLD, 12));
		}
		
		if (row == bestTimeIndex && column == 1) {
			c.setFont(font);
			c.setBackground(new Color(70, 83, 45));
		}
		
		if (row == bestTimeIndex && column == 2) {
			c.setFont(font);
			c.setBackground(new Color(70, 83, 45));
		}
		
		if (row == topSpeedIndex && column == 3) {
			c.setFont(font);
			c.setBackground(new Color(70, 83, 45));
		}
		
		if (row == avgSpeedIndex && column == 4) {
			c.setFont(font);
			c.setBackground(new Color(70, 83, 45));
		}
		
		if (row == minSpeedIndex && column == 5) {
			c.setFont(font);
			c.setBackground(new Color(70, 83, 45));
		}
		
		return c;
	}

	/**
	 * @param filas the filas to set
	 */
	public void setFilas(int filas) {
		this.filas = filas;
	}

	/**
	 * @param bestTimeIndex the bestTimeIndex to set
	 */
	public void setBestTimeIndex(int bestTimeIndex) {
		this.bestTimeIndex = bestTimeIndex;
	}

	/**
	 * @param topSpeedIndex the topSpeedIndex to set
	 */
	public void setTopSpeedIndex(int topSpeedIndex) {
		this.topSpeedIndex = topSpeedIndex;
	}

	/**
	 * @param avgSpeedIndex the avgSpeedIndex to set
	 */
	public void setAvgSpeedIndex(int avgSpeedIndex) {
		this.avgSpeedIndex = avgSpeedIndex;
	}

	/**
	 * @param minSpeedIndex the minSpeedIndex to set
	 */
	public void setMinSpeedIndex(int minSpeedIndex) {
		this.minSpeedIndex = minSpeedIndex;
	}
	
	
}
